#!/usr/bin/ruby
# -*- ruby -*-
#
# http://pastebin.com/raw.php?i=RwGxZWsz

require 'set'

Letters = Set.new(('a' .. 'z').to_a)

(input = STDIN.readlines.slice(1 .. -1)).each_index do |ind|
    line = input[ind].strip

    fr = {}

    line.split(//).each do |ch|
        ch = ch.downcase

        (fr[ch] ||= 0 ; fr[ch] = fr[ch] + 1) if
            Letters.include?(ch)
    end

    order = fr.to_a.sort { |a, b| b.last <=> a.last }

    score = order.zip((26 - order.size .. 26).to_a.reverse).
        inject(0) { |r, (fr, o)| r + fr.last * o }

    puts "Case #{ind + 1}: #{score}"
end
